package com.ray.mapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;

import com.ray.bean.OrderBean;
import com.ray.bean.OrderCustomTagBean;
import com.ray.bean.OrderInfoDetailBean;
import com.ray.bean.OrderInfoDetailSourceAndApplyBean;
import com.ray.bean.OrderInfoTemplateBean;

/**
 * 订单创建Mapper
 * @author Shensg
 * 2018年1月24日
 */
public interface OrderCreateApplyMapper {
	//获取订单信息列表
	List<Map> getOrderTabList(@Param("map")Map map);
	/*//获取原材料仓信息列表
	List<Map> getSourceFactoryTabList(@Param("map")Map map);	*/
	//获取原料等查询子节点信息
	List<Map> getFactoryTabChildList(@Param("map")Map<String, String> map);
	//存储订单模版
	int saveAsOrderTemplate(@Param("bean")OrderInfoTemplateBean bean);
	//获取基础数据
	List<Map> getDataBasicList(@Param("map")Map map);
	//通过id更新基础数据
	void updateDataBasicById(@Param("map")Map map);
	//获取不可编辑参数 订单编号等
	Map getOrderInfoFixed(@Param("map")Map map);
	//获取不可编辑参数 订单编号等
	Map getOrderApplyId();
	//保存订单主表
	int saveOrderInfo(@Param("map")Map map);
	//保存订单明细表
	int saveOrderInfoDetail(List<OrderInfoDetailBean> list);
	//保存订单明细tail表
	int saveOrderInfoTail(List<OrderInfoDetailBean> list);
	//保存订单和模版的关联
	int saveOrderInfoAndTemplate(@Param("order_no")String order_no,@Param("order_template_id") String order_template_id,@Param("apply_id") String apply_id);
	//通过订单号删除
	int deleteOrderInfo(@Param("order_no")String order_no);
	//通过订单号 删除订单模版关系
	void deleteOrderInfoAndTemplate(@Param("order_no")String order_no);
	//通过订单号获取数据
	Map<String,String> getOrderInfoByOrderNo(@Param("order_no")String order_no,@Param("apply_id")String apply_id);
	//通过订单号获取数据
	List<Map<String, Object>> getOrderInfoDetailByOrderNo(@Param("order_no")String order_no,@Param("apply_id")String apply_id);
	//通过订单号获取数据
	List<Map<String, Object>> getOrderInfoTailByOrderNo(@Param("order_no")String order_no,@Param("apply_id")String apply_id);
	//检查模版和订单号准确性
	int checkTempAndOrderNo(@Param("map")Map<String, Object> map);
	//检查订单是否已审核
	int getAuditTotalByOrderNo(@Param("map")Map<String, Object> map);
	//更新订单 --审核订单使用
	int updateAudit(Map map);
	//通过id删除模版
	int deleteTemplate(Map<String, Object> map);
	//通过code从materialTable 赋值到 companymaterialTable
	void insertCompanyMTbyCode(@Param("code")String code,@Param("company")String company);
	//通过bean 插入到companymaterialTable
	void insertCompanyMTbyBean(@Param("bean")OrderInfoDetailBean bean);
	//保存自定义标签表
	int saveOrderCustomTag(List<OrderCustomTagBean> list_orderCustomTag);
	//通过id获取自定义标签信息
	Map<String, String> getOrderCustomTagByOrderNo(@Param("order_no")String order_no,@Param("apply_id")String apply_id);
	//获取部门信息表
	List<Map> selectOnlineByDeptId(@Param("map")Map map);
	//通过参数获取生产订单主表数据
	List<Map> getOrderInfoByParam(@Param("map")Map map);
	//删除生产订单主表数据
	int updateOrderInfoPrimary(Map map);
	//通过部门id获取生产车间
	List<Map> selectOnlineForproductWorkNo(@Param("map")Map map);
	//检验申请人和审核人是不是同一个人
	int checkAuditTheSameOne(Map map);
	//保存my_apply信息
	int saveAsApplyInfo(Map<String, Object> map);
	//通过apply_id更新
	void updateApplyInfo(Map map);
	//保存my_audit信息
	void saveAsAuditInfo(Map map);
	//将原数据保存到审核中
	void insertOrderSourceToAudit(Map map);
	/**
	 * 将元数据写入审核表作为备份
	 */
	void insertOrderInfoTemplateSourceToAudit(Map map);
	void insertOrderTemplateLinkSourceToAudit(Map map);
	void insertOrderInfoCustomTagSourceToAudit(Map map);
	void insertOrderInfoTailSourceToAudit(Map map);
	void insertOrderInfoDetailSourceToAudit(Map map);
	void insertOrderInfoPrimarySourceToAudit(Map map);
	/**
	 * 将申请单写入 原数据表
	 */
	int insertOrderInfoTemplateApplyToSource(Map map);
	void insertOrderTemplateLinkApplyToSource(Map map);
	void insertOrderInfoCustomTagApplyToSource(Map map);
	void insertOrderInfoTailApplyToSource(Map map);
	void insertOrderInfoDetailApplyToSource(Map map);
	void insertOrderInfoPrimaryApplyToSource(Map map);
	//查询投料单明细
	Map<String,Object> selectFeedOrderDetail(@Param("lineNo")String lineNo, @Param("materialType")String materialType, @Param("materialFactory")String materialFactory,@Param("orderNo")String orderNo);
	//通过订单编号获取申请审核备注信息
	List<Map> getRemarkData(Map map);
	//通过订单编号获取投料数大于0的插入到订单明细中
	int saveOrderInfoDetailFromTail(@Param("order_no")String order_no,@Param("apply_id")String apply_id,@Param("order_total")String order_p_order_total);
	//通过申请人id获取审核人openId
	List<Map<String, String>> getOpenIdForAudit(@Param("loginUserId")String loginUserId,@Param("audit_type")String audit_type);
	//通过订单号通知申请人
	List<String> getOpenIdForApply(@Param("order_no")String order_no);
	//通过用户id获取发送模版消息内容
	List<Map<String, String>> getInfoForWeixinTemplate(List<String> userIds);
	//判断订单是否审核
	int getAuditTotalByApplyId(Map map);
	//获取订单明细元数据和申请修改数据
	List<OrderInfoDetailSourceAndApplyBean> getMaterialInfoForSourceAndApply(Map map);
	//通过订单明细获取对应订单的投料单信息
	Map getFeenOrderDetailByDetail(@Param("bean")OrderInfoDetailSourceAndApplyBean bean);
	//获取原材料仓出库数量
	List<Map> getSourceOutTotalByDetail(@Param("detailId")String detailId);
	//获取原材料仓退回数量
	List<Map> getSourceInTotalByDetail(@Param("bean")OrderInfoDetailSourceAndApplyBean bean);
	//通过投料单明细id获取采购单明细信息
	Map getPurchaseOrderByFeedOrderId(@Param("detailId")String detailId);
	//获取其他仓出库数量
	List<Map> getExceptSouceOutTotalByDetail(@Param("purchaseOrderId")String purchaseOrderId);
	//获取其他仓退回数量
	List<Map> getExceptSouceInTotalByDetail(String purchaseOrderId);
	//获取报工退回数量
	List<Map> getJobBookInTotalByDetail(@Param("bean")OrderInfoDetailSourceAndApplyBean bean);
	//更新申请表specialRemark
	void updateApplySpecialRemark(@Param("specialRemark")String specialRemark, @Param("applyId")String applyId);
	//通过投料单明细查询采购单detailId
	String getPurchaseOrderDetailIdByFeedDetailId(Map<String, Object> mapPurchaseOrder);
}
